Format US Phone Number
工作流概述
这是一个包含7个节点的中等工作流,主要用于自动化处理各种任务。
工作流源代码
{
"id": "mNbQmMNEvpiZqASG",
"meta": {
"instanceId": "f80e038bf7b8c99e3db7e7d6a34de2c19f0af25e5d7445b15c36d79b6e8e9e55"
},
"name": "Format US Phone Number",
"tags": [],
"nodes": [
{
"id": "bf150da4-5e01-4571-a606-10a0fb25004b",
"name": "When Executed by Another Workflow",
"type": "n8n-nodes-base.executeWorkflowTrigger",
"position": [
0,
275
],
"parameters": {
"workflowInputs": {
"values": [
{
"name": "Phone Number",
"type": "any"
}
]
}
},
"typeVersion": 1.1
},
{
"id": "7c560ecf-c827-413f-a115-7b6bc8f21a41",
"name": "Check if first digit is valid country code",
"type": "n8n-nodes-base.if",
"position": [
660,
275
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "4d5c838e-9b08-4466-b00d-c695fd76d66d",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json['Phone Number'].toString().slice(0,1).toNumber() }}",
"rightValue": 1
}
]
}
},
"typeVersion": 2.2
},
{
"id": "783d8fd0-2a38-41fc-87c9-b0aec9933070",
"name": "Add valid country code",
"type": "n8n-nodes-base.set",
"position": [
880,
475
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "e47a1812-f69c-4182-bed5-cf037071cd9b",
"name": "Phone Number",
"type": "number",
"value": "=1{{ $json['Phone Number'] }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "a93923f3-5d8d-4617-a63d-50b66b3b1128",
"name": "Strip phone number formatting",
"type": "n8n-nodes-base.set",
"position": [
220,
275
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "91d348df-6937-4118-8f7b-c9d386eb5c21",
"name": "Phone Number",
"type": "number",
"value": "={{ $json['Phone Number'].match(/[0-9]+/gmi).join('') }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "58d6d280-ec86-4b69-a89c-e43571ce1035",
"name": "Check number of digits in phone number",
"type": "n8n-nodes-base.switch",
"position": [
440,
254
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "Full Number",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "66c9d1e7-dc56-4ce8-b7e4-64274feb8750",
"operator": {
"type": "number",
"operation": "gte"
},
"leftValue": "={{ $json['Phone Number'].toString().length }}",
"rightValue": 11
}
]
},
"renameOutput": true
},
{
"outputKey": "Number",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "2b9be422-2c4d-402a-b598-e8ab55aa5196",
"operator": {
"type": "number",
"operation": "equals"
},
"leftValue": "={{ $json['Phone Number'].toString().length }}",
"rightValue": 10
}
]
},
"renameOutput": true
},
{
"outputKey": "Invalid Number",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "a442130a-f2f8-4399-8edb-180d3607ec9b",
"operator": {
"type": "number",
"operation": "lt"
},
"leftValue": "={{ $json['Phone Number'].toString().length }}",
"rightValue": 10
}
]
},
"renameOutput": true
},
{
"outputKey": "Not a Number",
"conditions": {
"options": {
"version": 2,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "efba5af9-dfe4-47f0-8e82-253accd4f238",
"operator": {
"type": "number",
"operation": "notExists",
"singleValue": true
},
"leftValue": "={{ $json['Phone Number'] }}",
"rightValue": ""
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.2
},
{
"id": "1f6a4aa7-0595-4db3-a9c3-dc7a72656597",
"name": "Format phone numbers",
"type": "n8n-nodes-base.set",
"position": [
1100,
325
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "402c8481-3dee-4b90-8a08-7e611156d012",
"name": "Phone Number (Input)",
"type": "string",
"value": "={{ $('When Executed by Another Workflow').item.json['Phone Number'] }}"
},
{
"id": "9bc193b1-664f-40c0-8545-6792b5599777",
"name": "Phone Number",
"type": "number",
"value": "={{ $json['Phone Number'].toString().slice(0,11).toNumber() }}"
},
{
"id": "a4944be5-bfd5-4804-aeb5-d84c59145485",
"name": "=Phone Number (E-164)",
"type": "string",
"value": "={{ $json['Phone Number'] ? '+' + $json['Phone Number'] : '' }}"
},
{
"id": "3a8d506c-45ba-4843-b186-78bf877b7903",
"name": "Phone Number (National)",
"type": "string",
"value": "={{ $json['Phone Number'] ? '(' + $json['Phone Number'].toString().slice(1,4) + ') ' + $json['Phone Number'].toString().slice(4,7) + '-' + $json['Phone Number'].toString().slice(7,11) : '' }}"
},
{
"id": "14daf876-5f94-44d7-915b-bc4a8d6afbc4",
"name": "Phone Number (Full National)",
"type": "string",
"value": "={{ $json['Phone Number'] ? '1 (' + $json['Phone Number'].toString().slice(1,4) + ') ' + $json['Phone Number'].toString().slice(4,7) + '-' + $json['Phone Number'].toString().slice(7,11) : '' }}"
},
{
"id": "3270cc41-bfd7-4c5d-a05e-4af8da028bd5",
"name": "Phone Number (International)",
"type": "string",
"value": "={{ $json['Phone Number'] ? '00-1-' + $json['Phone Number'].toString().slice(1,4) + '-' + $json['Phone Number'].toString().slice(4,7) + '-' + $json['Phone Number'].toString().slice(7,11) : '' }}"
},
{
"id": "a6bd3652-071f-41b6-b523-bca427ef54f5",
"name": "Extension",
"type": "number",
"value": "={{ $json['Phone Number'].toString().slice(11).toNumber() }}"
},
{
"id": "7b808bfb-0d69-410c-b8f4-cbf2cafcf7e8",
"name": "Extension (String)",
"type": "string",
"value": "={{ $json['Phone Number'].toString().slice(11).toNumber() > 0 ? $json['Phone Number'].toString().slice(11).toNumber() : '' }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "7bc3c1a0-2056-48a0-b826-21a8c1bff31b",
"name": "Clear invalid number",
"type": "n8n-nodes-base.set",
"position": [
880,
125
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "c8d90980-61c9-49c5-8769-32c445790328",
"name": "Phone Number",
"type": "string",
"value": ""
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
}
],
"active": false,
"pinData": {
"When Executed by Another Workflow": [
{
"json": {
"Phone Number": "1-800-555-5555"
}
},
{
"json": {
"Phone Number": "1.800.555.5555"
}
},
{
"json": {
"Phone Number": "800.555.5555"
}
},
{
"json": {
"Phone Number": "1.800.555.55551234"
}
},
{
"json": {
"Phone Number": "1(800)555-55"
}
},
{
"json": {
"Phone Number": "5(800)555-5555"
}
},
{
"json": {
"Phone Number": "1(800)555-5555 extension 1234"
}
},
{
"json": {
"Phone Number": "A string"
}
}
]
},
"settings": {
"executionOrder": "v1"
},
"versionId": "1b7626d5-b32b-41bd-989a-a79616769278",
"connections": {
"Clear invalid number": {
"main": [
[
{
"node": "Format phone numbers",
"type": "main",
"index": 0
}
]
]
},
"Format phone numbers": {
"main": [
[]
]
},
"Add valid country code": {
"main": [
[
{
"node": "Format phone numbers",
"type": "main",
"index": 0
}
]
]
},
"Strip phone number formatting": {
"main": [
[
{
"node": "Check number of digits in phone number",
"type": "main",
"index": 0
}
]
]
},
"When Executed by Another Workflow": {
"main": [
[
{
"node": "Strip phone number formatting",
"type": "main",
"index": 0
}
]
]
},
"Check number of digits in phone number": {
"main": [
[
{
"node": "Check if first digit is valid country code",
"type": "main",
"index": 0
}
],
[
{
"node": "Add valid country code",
"type": "main",
"index": 0
}
],
[
{
"node": "Clear invalid number",
"type": "main",
"index": 0
}
],
[
{
"node": "Clear invalid number",
"type": "main",
"index": 0
}
]
]
},
"Check if first digit is valid country code": {
"main": [
[
{
"node": "Format phone numbers",
"type": "main",
"index": 0
}
],
[
{
"node": "Clear invalid number",
"type": "main",
"index": 0
}
]
]
}
}
}
功能特点
- 自动检测新邮件
- AI智能内容分析
- 自定义分类规则
- 批量处理能力
- 详细的处理日志
技术分析
节点类型及作用
- Executeworkflowtrigger
- If
- Set
- Switch
复杂度评估
配置难度:
维护难度:
扩展性:
实施指南
前置条件
- 有效的Gmail账户
- n8n平台访问权限
- Google API凭证
- AI分类服务订阅
配置步骤
- 在n8n中导入工作流JSON文件
- 配置Gmail节点的认证信息
- 设置AI分类器的API密钥
- 自定义分类规则和标签映射
- 测试工作流执行
- 配置定时触发器(可选)
关键参数
| 参数名称 | 默认值 | 说明 |
|---|---|---|
| maxEmails | 50 | 单次处理的最大邮件数量 |
| confidenceThreshold | 0.8 | 分类置信度阈值 |
| autoLabel | true | 是否自动添加标签 |
最佳实践
优化建议
- 定期更新AI分类模型以提高准确性
- 根据邮件量调整处理批次大小
- 设置合理的分类置信度阈值
- 定期清理过期的分类规则
安全注意事项
- 妥善保管API密钥和认证信息
- 限制工作流的访问权限
- 定期审查处理日志
- 启用双因素认证保护Gmail账户
性能优化
- 使用增量处理减少重复工作
- 缓存频繁访问的数据
- 并行处理多个邮件分类任务
- 监控系统资源使用情况
故障排除
常见问题
邮件未被正确分类
检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。
Gmail认证失败
确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。
调试技巧
- 启用详细日志记录查看每个步骤的执行情况
- 使用测试邮件验证分类逻辑
- 检查网络连接和API服务状态
- 逐步执行工作流定位问题节点
错误处理
工作流包含以下错误处理机制:
- 网络超时自动重试(最多3次)
- API错误记录和告警
- 处理失败邮件的隔离机制
- 异常情况下的回滚操作